package com.my.meitianbackup.utils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class DBTools {
	private static Logger logger = LoggerFactory.getLogger("DBTools");

	public static void init100items() {
		List<Record> list = Db.find("select * from meitian where hasInfo = 1 and hasImgs = 1 and couponEnd > now() limit 100");
		Date date = new Date();
		for(int i=0; i<list.size(); i++) {
			list.get(i).set("publishDate", date);
		}
		int[] i = Db.batchUpdate("meitian", list, list.size());
		System.out.println("aaa:"+Arrays.toString(i));
	}
	
	public static String getLastNumFromString(String str) {
		String regex = "\\d*";
		Pattern p = Pattern.compile(regex);
		
		Matcher m = p.matcher(str);
		String s = null;
		while (m.find()) {
			if (!"".equals(m.group()))
				s = m.group();
		}
		return s;
		
	}
}
